package com.sportradar.assessment.work.core;


import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sportradar.assessment.work.beans.ConfigurationBean;
import com.sportradar.assessment.work.services.ExecutionManager;
import com.sportradar.assessment.work.services.MultiplicationFiveProgression;
import com.sportradar.assessment.work.services.NumberProgression;
import com.sportradar.assessment.work.threads.ExecutionThread;
import com.sportradar.assessment.work.threads.StatisticsReporterThread;
import com.sportradar.assessment.work.util.ConfigUtil;
import com.sportradar.assessment.work.util.Constants;

public class SportradarAssessment {

	private static Logger logger=LoggerFactory.getLogger(SportradarAssessment.class);
	
		
	public static void main(String[] args) {

		 NumberProgression numberProgression=new MultiplicationFiveProgression();
		
		 //1) Read configuration file and init ThreadManager
		 ConfigurationBean firstSettings=ConfigUtil.update();
		 ExecutionManager threadManager= new ExecutionManager(numberProgression,firstSettings);
		 
		 
		 //2) Thread configurations
		 String thread1Name=ConfigUtil.getPropertyValue(Constants.THREAD_1_NAME_KEY);
		 String thread2Name=ConfigUtil.getPropertyValue(Constants.THREAD_2_NAME_KEY);
		// long configurationRefreshRate=ConfigUtil.getPropertyValueAsLong(Constants.REFRESH_INTERVAL_KEY);
			
		 Runnable thread1=new ExecutionThread(thread1Name,threadManager);
		 Runnable thread2=new ExecutionThread(thread2Name,threadManager);
		 Runnable statisticsThread=new StatisticsReporterThread(threadManager);
			

		ScheduledThreadPoolExecutor executor= new ScheduledThreadPoolExecutor(3);
		executor.scheduleWithFixedDelay(statisticsThread,10,10, TimeUnit.SECONDS);
		executor.execute(thread1);
		executor.execute(thread2);

		

	}
	


	

}
